import request from '@/utils/request';

// 查询券列表
export function listCoupons({
  pageNum, pageSize, couponCode, couponStatus,
}) {
  return request.post('/web/coupon/listCoupons', {
    couponCode,
    couponStatus,
    pageNum,
    pageSize,
  });
}

// 新增券
export function addCoupon({ couponCode, couponPwd }) {
  return request.post('/web/coupon/addCoupon', {
    couponCode,
    couponPwd,
  });
}

// 修改券
export function updateCoupon({ couponId, couponCode, couponPwd }) {
  return request.post('/web/coupon/updateCoupon', {
    couponId,
    couponCode,
    couponPwd,
  });
}

// 查询订单列表
export function listOrders({
  pageNum, pageSize, receiveName, receivePhone, couponCode, orderStatus,
}) {
  return request.post('/web/order/listOrders', {
    pageNum,
    pageSize,
    receiveName,
    receivePhone,
    couponCode,
    orderStatus: parseInt(orderStatus, 10),
  });
}

// 修改订单状态
export function updateOrderStatus({ couponId, type, orderId }) {
  return request.post('/web/order/updateOrderStatus', {
    couponId,
    type,
    orderId,
  });
}

// 导出订单
export function exportOrderList({
  receiveName, receivePhone, couponCode, pageNum, pageSize,
}) {
  return request.post(
    '/web/order/exportOrder',
    {
      receiveName,
      receivePhone,
      couponCode,
      pageNum,
      pageSize,
    },
    {
      responseType: 'blob',
    },
  );
}

// 查询兑换券的时间
export function queryTimeConfig() {
  return request.post('/web/time-config/queryTimeConfig', {});
}

// 修改兑换券的时间
export function updateTimeConfig({ configId, startTime, endTime }) {
  return request.post('/web/time-config/updateTimeConfig', {
    configId,
    startTime,
    endTime,
  });
}

// 生成优惠券
export function generateCoupon({ amount }) {
  return request.post('/web/coupon/generateCoupon', null, {
    params: {
      amount,
    },
  });
}
// 删除优惠券
export function deleteCoupon({ couponId }) {
  return request.post('/web/coupon/deleteCoupon', null, {
    params: {
      couponId,
    },
  });
}

// 设置订单备注
export function updateOrderRemark({ orderId, orderRemark }) {
  return request.post('/web/order/updateOrderRemark', {
    orderId,
    orderRemark,
  });
}

// 导出券码列表
export function exportCoupon({ couponCode, couponStatus }) {
  return request.post(
    '/web/coupon/exportCoupon',
    {
      couponCode,
      couponStatus,
    },
    {
      responseType: 'blob',
    },
  );
}

// 批量删除优惠券
export function batchDeleteCoupon({ couponIds }) {
  return request.post('/web/coupon/batchDeleteCoupon', null, {
    params: {
      couponIds,
    },
  });
}

// 修改券码备注
export function updateCouponRemark({ couponId, couponRemark }) {
  return request.post('/web/coupon/updateCouponRemark', {
    couponId,
    couponRemark,
  });
}

// 登录
export function login({ userName, userPassword }) {
  return request.post('/web/user/login', {
    userName,
    userPassword,
  });
}

// 修改用户信息
export function updateUser({ userInfoId, userName, userPassword }) {
  return request.post('/web/user/updateUser', {
    userInfoId,
    userName,
    userPassword,
  });
}

/**
 * 查询通知
 */
export function reqGetNotice() {
  return request.get('/web/message/queryMessage');
}

/**
 * 更新通知
 */
export function reqUpdateNotice({ messageId, messageContents, hiddenFlag }) {
  return request.post('/web/message/updateMessage', {
    messageId,
    messageContents,
    hiddenFlag,
  });
}

// 批量删除订单
export function batchDeleteOrder({ orderIds }) {
  return request.post('/web/order/batchDeleteOrder', null, {
    params: {
      orderIds,
    },
  });
}
